Skip to content

Implement Hash for RoaringBitmap and RoaringTreemap - #365

Open
ChrisJr404 wants to merge 1 commit into
RoaringBitmap:mainfrom
ChrisJr404:make-hash
Open

Implement Hash for RoaringBitmap and RoaringTreemap#365
ChrisJr404 wants to merge 1 commit into
RoaringBitmap:mainfrom
ChrisJr404:make-hash

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #231.

RoaringBitmap and RoaringTreemap implement Eq but not Hash, so they can't be used as keys in a HashMap or HashSet.

A derive won't work for RoaringBitmap, because two bitmaps holding the same values are equal even when their containers use different internal representations (array, bitmap or run). The hash is built from the values via the existing iterator so it stays consistent with PartialEq whatever the layout. RoaringTreemap just derives it, as suggested in the issue, since it's a BTreeMap of bitmaps.

Tests live in tests/hash.rs and tests/treemap_hash.rs and cover the case where the same values are stored in different representations (optimized vs not) and still hash equal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Hash

1 participant